<template>
  <div>
    <p :style="{ opacity: opt }">数字是:{{ count }}</p>
    <button @click="count++">点击+1</button>
    <button @click="getDestory">卸载组件</button>
    <Teacher :school="school" :goSchool="goSchool" />
    <Student :school="school" />
  </div>
</template>
<script>
import Teacher from "@/components/Teacher";
import Student from "@/components/Student";
export default {
  name: "App",
  // 注册
  components: { Teacher, Student },
  data() {
    return {
      count: 0,
      opt: 1,
      school: "清华大学",
    };
  },
  methods: {
    getDestory() {
      this.$destroy();
    },
    goSchool() {
      this.school = "北京大学";
    },
  },
  // beforeCreate初始化之前
  // 挂载完成前 数据已经有了
  beforeMount() {
    console.log(this.count);
  },
  // 将内存中的虚拟dom转为真实dom插入页面
  // 挂载完成后
  mounted() {
    setInterval(() => {
      this.opt -= 0.1;
      if (this.opt < 0) {
        this.opt = 1;
      }
    }, 100);
  },
};
</script>
<style>
</style>